package com.gscitysfy.cus.drain.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 统一时间格式转换
 * @author Administrator
 */
@Component
@Slf4j
public class DateConverter implements Converter<String, Date> {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public Date convert(@NotNull String source) {
        try {
            if(!StringUtils.isEmpty(source)){ return sdf.parse(source);}
        } catch (ParseException e) {
            log.error("时间格式转换错误......!");
        }
        return null;
    }
}

